import 'package:beautyflutter/componts/loading.dart';
import 'package:beautyflutter/componts/tab_navigator.dart';
import 'package:beautyflutter/pages/login/login.dart';
import 'package:beautyflutter/pages/news/news_page.dart';
import 'package:flare_splash_screen/flare_splash_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:oktoast/oktoast.dart';

void main() {
  runApp(MyApp());
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return OKToast(
      textStyle: TextStyle(fontSize: 19.0, color: Colors.white),
      backgroundColor: Colors.grey,
      radius: 10.0,
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          // This is the theme of your application.
          //
          // Try running your application with "flutter run". You'll see the
          // application has a blue toolbar. Then, without quitting the app, try
          // changing the primarySwatch below to Colors.green and then invoke
          // "hot reload" (press "r" in the console where you ran "flutter run",
          // or simply save your changes to "hot reload" in a Flutter IDE).
          // Notice that the counter didn't reset back to zero; the application
          // is not restarted.
          primarySwatch: Colors.blue,
        ),
        home: SplashScreen.navigate(
          name: 'assets/intro.flr',
          next: (context) => LoadingPage(),
  //          new WillPopScope(
  //            child: LoadingPage(),
  //            onWillPop: () async {
  //              if(lastPopTime == null || (DateTime.now().difference(lastPopTime) > Duration(seconds: 1))){
  //              //两次点击间隔超过1秒，重新计时
  //                lastPopTime = DateTime.now();
  //                print(lastPopTime);
  //                return false;
  //              }
  //              return true;
  //            }
  //        ),
          until: () => Future.delayed(Duration(seconds: 2)),
          startAnimation: '1',
        ),
        routes: {
          'tab_natigator': (context) => TabNatigator(),
          'request_data': (context) => RequestData(),
          'login': (context) => Login()
        },
      )
    );
  }
}
